<?php
include "../config/connection.inc";
function getDegrees(){
    $query = "select * from DEGREES";
    return mysql_query($query);
}

function searchRecruiment($search) {
        $query = "select * from RECRUITMENTS RC
                join POSITIONS PS on RC.POSITION_ID = PS.POSITION_ID 
                join JOB_LOCATION JL on RC.JOB_LOC_ID = JL.JOB_LOC_ID
                join DEGREES DG on RC.DEGREE_ID = DG.DEGREE_ID
                join MAJORS MJ on RC.MAJOR_ID = MJ.MAJOR_ID  
                where 1 = 1"; 
                if ($search['position'] != 0) {
                    $query .= " and RC.POSITION_ID = '".$search['position']."'";
                }
                if ($search['location'] != 0) {
                    $query .= " and RC.JOB_LOC_ID = '".$search['location']."'";
                }
                if ($search['degree'] != 0) {
                    $query .= " and RC.DEGREE_ID = '".$search['degree']."'";
                }
                if ($search['major'] != 0) {
                    $query .= " and RC.MAJOR_ID = '".$search['major']."'";
                }
        return mysql_query($query);
    }

function getAllRecruitmentOfCompany($companyId){
    $query = "select * from RECRUITMENTS where USER_ID = $companyId";
    return mysql_query($query);
}

function getRecruitment($id){
    $query = "select * from RECRUITMENTS where RECRUITMENT_ID = $id";
    return mysql_query($query);
}

function addRecruitment($companyId, $title, $location, $major, $position, $degree, $description){
    $query = "INSERT INTO RECRUITMENTS(RECRUITMENT_NAME, USER_ID, MAJOR_ID, JOB_LOC_ID, DEGREE_ID, POSITION_ID, RECRUITMENT_DESCRIPTION)
                VALUES('$title', $companyId, $major, $location, $degree, $position, '$description')";
                echo "<br/>".$query;
    mysql_query($query);
}

function updateRecruitment($companyId, $recruitmentId, $title, $location, $major, $position, $degree, $description){
    $query = "UPDATE RECRUITMENTS SET RECRUITMENT_NAME = '$title', MAJOR_ID = $major, JOB_LOC_ID = $location, DEGREE_ID = $degree, POSITION_ID = $position, RECRUITMENT_DESCRIPTION = '$description'
                WHERE USER_ID = $companyId AND RECRUITMENT_ID = $recruitmentId";
    mysql_query($query);
}
?>